﻿using System.Windows;
using System.Collections.Generic;
using FireFly;
using System.Collections;

namespace XAMLStylePad.ViewModels.TriggersAndSetters
{
    public class EventTriggerViewModel : TriggerViewModelBase<EventTrigger>
    {
        public EventTriggerViewModel(EventTrigger EventTrigger)
            : base(EventTrigger)
        {

        }

        #region RoutedEvent
        public RoutedEvent RoutedEvent
        {
            get
            {
                return Model.RoutedEvent;
            }
            set
            {
                Model.RoutedEvent = value;
                OnPropertyChanged("RoutedEvent");
            }
        }
        #endregion

        #region SourceName
        public string SourceName
        {
            get
            {
                return Model.SourceName;
            }
            set
            {
                Model.SourceName = value;
                OnPropertyChanged("SourceName");
            }
        }
        #endregion

        #region Actions
        public CollectionViewModel<TriggerAction, ObjectViewModel> Actions
        {
            get
            {
                if(_Actions == null)
                {
                    _Actions = new CollectionViewModel<TriggerAction, ObjectViewModel>(Model.Actions, o => new ObjectViewModel(o))
                    {
                        Parent = this,
                        DisplayName = "Actions"
                    };
                }
                return _Actions;
            }
        }
        CollectionViewModel<TriggerAction, ObjectViewModel> _Actions;
        #endregion

        public override string DisplayName
        {
            get
            {
                return "on " + (string.IsNullOrEmpty(SourceName) ? "" : SourceName + ".") + string.Format("{0} [{1} setter(s)]", RoutedEvent.Name, Actions != null ? Actions.Count : 0);
            }
        }

        public override ICollection VisualChildren
        {
            get
            {
                return ViewModelService.Instance.CombineVisualChildren(EnterActions, ExitActions, Actions);
            }
        }
    }
}